package com.hlhj.funlike_business.moudle;

import android.content.Context;

import com.example.mymvp.mvp.BaseModule;
import com.hlhj.funlike_business.api.Apis;
import com.hlhj.funlike_business.api.BaseObser;
import com.hlhj.funlike_business.bean.MsgBean;
import com.hlhj.funlike_business.bean.ShopInfoBean;
import com.hlhj.funlike_business.bean.ShopPhotoBean;
import com.hlhj.funlike_business.bean.UpImgBean;
import com.hlhj.funlike_business.bean.UpImgBean1;
import com.lzy.okgo.model.Response;

import java.io.File;
import java.util.List;

public class PhotoMoudle implements BaseModule{
    public interface getPhoto{
        void loadPhoto(List<ShopPhotoBean.DataBean> dataBeans);

        void loadUpImgResult(UpImgBean1.DataBean dataBean);

        void loadDelResult(String msg);
    }

    public getPhoto listener;

    public void setListener(getPhoto listener) {
        this.listener = listener;
    }


    public void LoadPhoto(Context context){
        Apis.INSTANCE.ShopPhoto()
                .subscribe(new BaseObser<Response<ShopPhotoBean>>(context) {
                    @Override
                    public void httpSuccess(Response<ShopPhotoBean> shopPhotoBeanResponse) {
                        if (listener!=null){
                            listener.loadPhoto(shopPhotoBeanResponse.body().getData());
                        }
                    }
                });
    }

    //读取资质相片
    public void LoadQualifactionAblums(Context context){
        Apis.INSTANCE.QualifacationAblums()
                .subscribe(new BaseObser<Response<ShopPhotoBean>>(context) {
                    @Override
                    public void httpSuccess(Response<ShopPhotoBean> shopPhotoBeanResponse) {
                        if (listener!=null){
                            listener.loadPhoto(shopPhotoBeanResponse.body().getData());
                        }
                    }
                });
    }

    //上传相册照片
    public void LoadUpImgResult(Context context,File image){
        Apis.INSTANCE.UpShopImg(image)
                .subscribe(new BaseObser<Response<UpImgBean1>>(context) {
                    @Override
                    public void httpSuccess(Response<UpImgBean1> msgBeanResponse) {
                        if (listener!=null){
                            listener.loadUpImgResult(msgBeanResponse.body().getData());
                        }
                    }
                });
    }

    //上传资质相片
    public void LoadUpQualificationImg(Context context,File shop){
        Apis.INSTANCE.UpQualificationsImg(shop)
                .subscribe(new BaseObser<Response<UpImgBean1>>(context) {
                    @Override
                    public void httpSuccess(Response<UpImgBean1> upImgBean1Response) {
                        if (listener!=null){
                            listener.loadUpImgResult(upImgBean1Response.body().getData());
                        }
                    }
                });
    }

    //删除图片
    public void LoadDelImg(Context context,int id,int slide_id){
        Apis.INSTANCE.DelImage(id,slide_id)
                .subscribe(new BaseObser<Response<MsgBean>>(context) {
                    @Override
                    public void httpSuccess(Response<MsgBean> msgBeanResponse) {
                        if (listener!=null){
                            listener.loadDelResult(msgBeanResponse.body().getMsg());
                        }
                    }
                });
    }
}
